package com.littlecar.business.controller;

import com.littlecar.business.service.ProductService;
import com.littlecar.common.entity.product.Product;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 描述：
 *
 * @author littlecar
 * @date 2020/2/27 15:19
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ResponseBody
    @RequestMapping("/getAllProducts")
    public List<Product> getAllProduct(@RequestParam("type")String type) {
        if (StringUtils.equals(type, "primary")) {
            return productService.getAllPrimaryProducts();
        } else if (StringUtils.equals(type, "foreign")) {
            return productService.getAllForeignProducts();
        }else{
            return null;
        }
    }
}
